<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        #imglist img{
            width: 300px;
            height: 200px;
            background: url('./imgs/loading.gif') no-repeat center center;
        }
    </style>
</head>
<body>
    <h1>图片延迟加载</h1>
    <hr>
    
    <!-- 1. 提高用户的体验 -->
    <!-- 2. 给服务器的QQ 留有更多的响应时间 -->
    
    <div id="imglist">
        <img data-src="./imgs/Meinv001.jpg">
        <img data-src="./imgs/Meinv002.jpg">
        <img data-src="./imgs/Meinv003.jpg">
        <img data-src="./imgs/Meinv004.jpg">
        <img data-src="./imgs/Meinv005.jpg">
        <img data-src="./imgs/Meinv006.jpg">
        <img data-src="./imgs/Meinv007.jpg">
        <img data-src="./imgs/Meinv008.jpg">
        <img data-src="./imgs/Meinv009.jpg">
        <img data-src="./imgs/Meinv010.jpg">
        <img data-src="./imgs/Meinv011.jpg">
        <img data-src="./imgs/Meinv012.jpg">
        <img data-src="./imgs/Meinv013.jpg">
        <img data-src="./imgs/Meinv014.jpg">
        <img data-src="./imgs/Meinv015.jpg">
    </div>


    <script>
        setTimeout(function(){
            // 获取所有的图片
            var imgs = document.getElementById('imglist').children;
            // console.log(imgs);
            // 遍历
            for (var i = 0; i < imgs.length; i++) {
                imgs[i].src = imgs[i].getAttribute('data-src');
            }
        }, 2000);

    </script>



</body>
</html>



